package main

import (
	"fmt"
	"log"
	"time"

	"github.com/gomodule/redigo/redis"
)

//redis 初始操作 非使用线程池
func main() {
	setdb := redis.DialDatabase(1)
	setPasswd := redis.DialPassword("ffdd2021@")
	timeout := redis.DialConnectTimeout(5 * time.Second)
	readTimeOut := redis.DialReadTimeout(5 * time.Second)
	writeTimeOut := redis.DialWriteTimeout(5 * time.Second)

	conn, err := redis.Dial("tcp", "81.68.186.20:6379", setdb, setPasswd, timeout, readTimeOut, writeTimeOut)
	if err != nil {
		fmt.Println("redis.Dial err = ", err)
		return
	}
	defer conn.Close()

	//设置key-value
	set, err := redis.String(conn.Do("set", "ding_test", "redigo"))
	if err != nil {
		log.Fatal("redis.String err = ", err)
	} else {
		log.Println("set key test redigo succeed! set = ", set)
	}

	//取出value并转成字符串
	get, err := redis.String(conn.Do("get", "ding_test"))
	if err != nil {
		log.Fatal("redis.String err = ", err)
	} else {
		log.Fatal("redis.String succeed get = ", get)
	}
}
